package net.oschina.bilbodai.common.beanutil.bean.code;

import net.oschina.bilbodai.common.beanutil.bean.core.PropertyDumpInfo;
import net.oschina.bilbodai.common.beanutil.util.TypeUtil;
import org.objectweb.asm.MethodVisitor;

/**
 * @author daimao  Date: 16/5/28 Time: 下午4:34
 * @version $Id$
 */
public class ReferenceToPrimeApplier extends DumpOverrideAwareApplier {

    public ReferenceToPrimeApplier(PropertyDumpInfo dumpInfo) {
        super(dumpInfo);
    }

    @Override
    protected void loadSrcCastPropertyOntoStack(MethodVisitor mv) {
        loadSrcCastPropertyOntoStack0(mv);
    }

    @Override
    protected void doApply(MethodVisitor mv) {
        loadTargetCastOntoStack0(mv); // load foo

        loadSrcCastPropertyOntoStack(mv); // get bar age(Integer)

        TypeUtil.TypeHolder boxHolder = TypeUtil.getBoxingTypeByInternalName(dumpInfo.getTargetFieldInternalName());
        boxHolder.applyPrimValueCode(mv);

        invokeTargetPropertySetter0(mv);
    }

}